package com.wx.controller;

import com.alibaba.fastjson.JSONObject;
import com.wx.model.UserModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

@RestController
@RequestMapping
public class Login {
    @Autowired
    com.wx.service.IUserService IUserService;

    @PostMapping("/login")
    public JSONObject login(@RequestBody UserModel userModel, HttpSession session){
        String code= (String) session.getAttribute("code");
        userModel.setSessionCode(code);
        int result= IUserService.login(userModel);
        if (result==1){
            String username=userModel.getUsername();
            session.setAttribute("username",username);
        }
        JSONObject jsonObject=new JSONObject();
        jsonObject.put("result",result);
        return jsonObject;
    }


}
